home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
002
/
findasci.arc
/
FINDASCI.C
next >
Wrap
Text File
|
1987-03-18
|
3KB
|
142 lines
#include "c:\lc\stdio.h"
#define DEFSEN 3
#define MAXSEN 50
#define CR 13
#define LF 10
#define TAB 9
#define SPC 32
#define ANULL 127
#define ARROW 16
main(argc, argv)
int argc;
char *argv[];
{
int l;
int c;
int oldc;
int cnt;
int sav[MAXSEN];
int crcount;
int sen;
int sensitivity;
FILE *fp, *fopen();
sen = DEFSEN;
cnt = 0;
crcount = 0;
c = NULL;
oldc = NULL;
l = 0;
sensitivity = atoi(argv[2]);
if (argc < 2 || argc > 3) {
printf ("\n");
printf ("\n Command line format: FINDASCI <filename> <sensitivity>\n");
printf ("\n FINDASCI v1.1, by Peter Nelson. \n");
printf ("\n This program will search through <filename>, and \n");
printf (" display all the ascii characters found. <Sensitivity> \n");
printf (" is how many CONSECUTIVE ascii characters to find before\n");
printf (" displaying them. The default is 3, hence HI will \n");
printf (" not produce any output, but MAN will produce MAN . \n");
printf (" The higher the number, the less garbage you will get, \n");
printf (" the greater the chance of missing some data. A lower \n");
printf (" number will show more data, but also more garbage. \n");
printf (" ENJOY! Finis, Mongo \n\n");
}
else {
if ((fp = fopen(argv[1], "rb")) == NULL)
printf ("\nError opening file: %s\n", argv[1]);
else {
if ((argc == 3) && (sensitivity < 1 || sensitivity > MAXSEN)) {
printf ("\n<sensitivity> must be between 1 & %d.\n", MAXSEN);
}
else {
if (argc==3)
sen = sensitivity;
c = getc(fp) ;
while (c != EOF) {
if ((c >= SPC && c <= ANULL) || (c==TAB) || (c==CR) || (c==LF)) {
if (c == LF && oldc != CR)
c = NULL;
if ((c == CR) || (c == LF && oldc != CR))
c = '\n';
if (c == ANULL)
c = NULL;
if (c == TAB)
c = ARROW;
if (cnt < sen) {
sav[cnt] = c;
if (++cnt == sen)
for (l = 0; l < (sen-1) ; ++l)
crcount = writeit(sav[l], crcount);
}
if (cnt == sen)
crcount = writeit(c, crcount);
}
else
cnt = 0;
oldc = c;
c = getc(fp);
}
if (cnt > 0 && cnt != sen) {
for (l = 0; l < cnt ; ++l)
crcount = writeit(sav[l], crcount);
}
}
}
}
}
writeit(c, crcount)
int c;
int crcount;
{
int justforced;
if (c != NULL) {
if (c != '\n' || c == '\n' && justforced != 1)
putchar(c);
if (c == '\n')
crcount = -1;
if (++crcount >= 80) {
putchar('\n');
crcount = 0;
justforced = 1;
}
else
justforced = 0;
}
return (crcount);
}
atoi(s)
char s[];
{
int i, n;
n = 0;
for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i)
n = 10 * n + s[i] - '0';
return(n);
}